# -----------------------------------------------------------------------------
# Copyright (c) 2025, Southeast University (China)
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are
# met:
#  - Redistributions of source code must retain the above copyright
#    notice, this list of conditions and the following disclaimer.
#  - Redistributions in binary form must reproduce the above copyright
#    notice, this list of conditions and the following disclaimer in the
#    documentation and/or other materials provided with the distribution.
#  - Neither the name of the copyright holders nor the names of its
#    contributors may be used to endorse or promote products derived from
#    this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#
# Authors: Jiajie Xu, Yanfang Zhang, Jiaqi Gao, Leyun Tian
# -----------------------------------------------------------------------------


# written by jiajiexu 25/3/25
puts [format "%-12s %-12s %-12s %-12s %-12s %-30s %-30s %-30s %-30s %-30s" "Max_Rise" "Max_Fall" "Min_Rise" "Min_Fall" "is_cellarc" "sense_unate" "from_pin" "to_pin" "when" "sdf_cond"]
puts [string repeat "-" 200]
foreach_in_collection cell [get_cells *] {

    set full_name [get_attribute $cell full_name]

    set arcs [get_timing_arcs -of $full_name]

    foreach_in_collection arc $arcs {
        set is_cellarc [get_attribute $arc is_cellarc]

        set sense_unate [get_attribute $arc sense]

        set sdf_cond [get_attribute -quiet $arc sdf_cond]
        if { $sdf_cond eq "" } { set sdf_cond "*" }

        set when [get_attribute -quiet $arc when]
            if { $when eq "" } { set when "*" }

        set fpin [get_attribute $arc from_pin]
        set from_pin_name [get_attribute $fpin full_name]

        set tpin [get_attribute $arc to_pin]
        set to_pin_name [get_attribute $tpin full_name]
        
        set max_rise [get_attribute -quiet $arc delay_max_rise]
        if { $max_rise eq "" } { set max_rise "*" }

        set max_fall [get_attribute -quiet $arc delay_max_fall]
        if { $max_fall eq "" } { set max_fall "*" }

        set min_rise [get_attribute -quiet $arc delay_min_rise]
        if { $min_rise eq "" } { set min_rise "*" }

        set min_fall [get_attribute -quiet $arc delay_min_fall]
        if { $min_fall eq "" } { set min_fall "*" }

        puts [format "%-12s %-12s %-12s %-12s %-12s %-30s %-30s %-30s %-30s %-30s" $max_rise $max_fall $min_rise $min_fall $is_cellarc $sense_unate $from_pin_name $to_pin_name $when $sdf_cond]
    }
}

foreach_in_collection cell [get_nets *] {

    set full_name [get_attribute $cell full_name]

    set sense_unate *

    set arcs [get_timing_arcs -of $full_name]

    foreach_in_collection arc $arcs {

        set sdf_cond [get_attribute -quiet $arc sdf_cond]
            if { $sdf_cond eq "" } { set sdf_cond "*" }

        set when [get_attribute -quiet $arc when]
            if { $when eq "" } { set when "*" }

        set is_cellarc [get_attribute $arc is_cellarc]

        set fpin [get_attribute $arc from_pin]
        set from_pin_name [get_attribute $fpin full_name]

        set tpin [get_attribute $arc to_pin]
        set to_pin_name [get_attribute $tpin full_name]

        set max_rise [get_attribute -quiet $arc delay_max_rise]
        if { $max_rise eq "" } { set max_rise "*" }

        set max_fall [get_attribute -quiet $arc delay_max_fall]
        if { $max_fall eq "" } { set max_fall "*" }

        set min_rise [get_attribute -quiet $arc delay_min_rise]
        if { $min_rise eq "" } { set min_rise "*" }

        set min_fall [get_attribute -quiet $arc delay_min_fall]
        if { $min_fall eq "" } { set min_fall "*" }

        puts [format "%-12s %-12s %-12s %-12s %-12s %-30s %-30s %-30s %-30s %-30s" $max_rise $max_fall $min_rise $min_fall $is_cellarc $sense_unate $from_pin_name $to_pin_name $when $sdf_cond]
    }
}

# proc show_arcs {args} {
#     set arcs [eval [concat get_timing_arcs $args]]
#     echo [format "%15s    %-15s  %8s %8s  %s" "from_pin" "to_pin" \
#                 "rise" "fall" "is_cellarc"]
#     echo [format "%15s    %-15s  %8s %8s  %s" "--------" "------" \
#                 "----" "----" "----------"]

#     foreach_in_collection arc $arcs {
#         set is_cellarc [get_attribute $arc is_cellarc]
#         set fpin [get_attribute $arc from_pin]
#         set tpin [get_attribute $arc to_pin]
#         set rise [get_attribute $arc delay_max_rise]
#         if { $rise eq "" } { set rise "*" }
#         set fall [get_attribute $arc delay_max_fall]
#         if { $fall eq "" } { set fall "*" }

#         set from_pin_name [get_attribute $fpin full_name]

#         set to_pin_name [get_attribute $tpin full_name]
#         echo [format "%15s -> %-15s  %8s %8s  %s" \
#             $from_pin_name $to_pin_name \
#             $rise $fall \
#             $is_cellarc]
#     }
# }